package net.pimpas.web.jsf.components.datepicker;

import javax.faces.component.UIComponent;

import org.apache.myfaces.taglib.html.ext.HtmlInputTextTag;

public class UIDatePickerTag extends HtmlInputTextTag {
	
	
	private Integer firstDayOfWeek;
	private Boolean showWeekNumbers;
	private String dateFormat;
	private String onSelected;
	private String onClosed;
	private String theme;
	
	@Override
	protected void setProperties(UIComponent component) {
		UIDatePicker datePicker = (UIDatePicker) component;
		if(this.getFirstDayOfWeek() == null || this.getFirstDayOfWeek() > 7)
			this.setFirstDayOfWeek(UIDatePicker.DEFAULT_FIRST_DOW);
		if(this.getShowWeekNumbers()==null)
			this.setShowWeekNumbers(UIDatePicker.DEFAULT_SHOW_WN);
		if(this.getDateFormat() == null)
			this.setDateFormat(UIDatePicker.DEFAULT_DATE_FORMAT);
		
		if(this.getTheme() == null)
			this.setTheme(UIDatePicker.DEFAULT_THEMES[UIDatePicker.DEFAULT_THEME_INDEX]);
		
		datePicker.setTheme(this.getTheme());
		datePicker.setFirstDayOfWeek(this.getFirstDayOfWeek());
		datePicker.setShowWeekNumbers(this.getShowWeekNumbers());
		datePicker.setDateFormat(this.getDateFormat());
		datePicker.setOnSelected(this.getOnSelected());
		datePicker.setOnClosed(this.getOnClosed());
		
		super.setProperties(component);
	}
	
	@Override
	public String getComponentType() {
		return UIDatePicker.COMPONENT_TYPE;
	}

	public String getDateFormat() {
		return dateFormat;
	}

	public void setDateFormat(String dateFormat) {
		this.dateFormat = dateFormat;
	}

	public Integer getFirstDayOfWeek() {
		return firstDayOfWeek;
	}

	public void setFirstDayOfWeek(Integer firstDayOfWeek) {
		this.firstDayOfWeek = firstDayOfWeek;
	}

	public String getOnClosed() {
		return onClosed;
	}

	public void setOnClosed(String onClosed) {
		this.onClosed = onClosed;
	}

	public String getOnSelected() {
		return onSelected;
	}

	public void setOnSelected(String onSelected) {
		this.onSelected = onSelected;
	}

	public Boolean getShowWeekNumbers() {
		return showWeekNumbers;
	}

	public void setShowWeekNumbers(Boolean showWeekNumbers) {
		this.showWeekNumbers = showWeekNumbers;
	}

	public String getTheme() {
		return theme;
	}

	public void setTheme(String theme) {
		if(theme != null) theme = theme.toLowerCase();
		this.theme = theme;
	}
}